<?php

declare(strict_types=1);

namespace App\Controller;

use App\HscoinConf;
use App\Model\PriceMonthly;
use App\Service\FundCacheService;
use App\Service\FundConfService;
use App\Service\FundBillService;
use App\Service\HscoinBillService;
use App\Service\HscoinBalanceService;

use App\Service\PriceDailyService;
use App\Service\PriceHourlyService;
use App\Service\PriceHourService;
use App\Service\PriceLogService;
use App\Service\PriceMonthlyService;
use App\Service\PriceWeekService;
use function Hyperf\Config\config;
use function Hyperf\Support\env;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;


class PriceController extends AbstractController
{

    #[Inject]
    private PriceLogService $service;

    #[Inject]
    private PriceHourlyService $hourlyService;
    #[Inject]
    private PriceDailyService $dailyService;
    #[Inject]
    private PriceWeekService $weekService;
    #[Inject]
    private PriceMonthlyService $monthlyService;

    function changeByHscoin()
    {
        $amount = $this->request->post('amount', 0);
        $id = $this->request->post('id', 0);
        $log = $this->service->changeByHscoin($amount, $id);
        //$this->dailyService->handle($log);
        return $this->jsonSuccess(compact('log', 'id', 'amount'));
    }

    function changeByFund()
    {
        $amount = $this->request->post('amount', 0);
        $id = $this->request->post('id', 0);
        $log = $this->service->changeByFund($amount, $id);
        //$this->dailyService->handle($log);
        return $this->jsonSuccess(compact('log', 'id', 'amount'));
    }

    function getPrice()
    {
        $info = $this->service->getPriceInfo();
        unset($info['fund_balance'], $info['hscoin_balance']);
        return $this->jsonSuccess($info);
    }

    function getPriceInfo()
    {
        $info = $this->service->getPriceInfo();
        return $this->jsonSuccess($info);
    }

    function listDaily()
    {
        $rs = $this->dailyService->listRows($this->request->input('limit'));
        return $this->jsonSuccess(['list' => $rs]);
    }

    function listWeekly()
    {
        $rs = $this->weekService->listRows($this->request->input('limit'));
        return $this->jsonSuccess(['list' => $rs]);
    }

    function listMonthly()
    {
        $rs = $this->monthlyService->listRows($this->request->input('limit'));
        return $this->jsonSuccess(['list' => $rs]);
    }

    function listHourly()
    {
        $rs = $this->hourlyService->listRows($this->request->input('limit'));
        return $this->jsonSuccess(['list' => $rs]);
    }
}
